'''
https://leetcode.cn/problems/minimum-size-subarray-sum/
'''
from typing import List


class Solution:
    def minSubArrayLen(self, target: int, nums: List[int]) -> int:
        n = len(nums)
        l = r = sum = 0
        ans = float('inf')
        while r < n:
            sum += nums[r]
            while l <= r and sum >= target:
                ans = min(ans, r - l + 1)
                sum -= nums[l]
                l += 1
            r += 1
        return ans if ans != float('inf') else 0